package leecode

func myPow(x float64, n int) float64 {
	if x == 1 || n == 0 {
		return 1
	}
	flag := 1
	//指数小于0
	if n < 0 {
		flag = 0
		n = -n
	}
	temp := myPow(x, n/2) //递归调用
	var result float64
	if n%2 == 0 {
		result = temp * temp
	}
	if n%2 == 1 {
		result = temp * temp * x
	}
	if flag == 0 {
		return 1 / result
	}
	return result
}
